<?php if ( ! defined('BASEPATH')) exit('This file does not run directly. Sorry.'); ?>
<?php
/**
 * Kalaisoo.
 *
 * A lightweight no-framework framework written in PHP.
 *
 * @package Kalaisoo
 * @author $Author: info@sah-company.com $
 * @version $Id: entry.php 130 2012-01-14 13:29:27Z info@sah-company.com $
 */

/**
 * Kalaisoo Entry Model Class.
 *
 * @package Kalaisoo
 * @subpackage Model
 * @author $Author: info@sah-company.com $
 */
class Model_Entry extends Model
{
	/**
	 * the record that this entry escorts.
	 *
	 * @var Model
	 */
	protected $record;
	
	/**
	 * __construct.
	 */
	public function construct()
	{
		parent::__construct();
	}
	
	/**
	 * returns the tags of a bean.
	 *
	 * @return array
	 */
	public function getTags() {
		return array(
		);
	}
	
	/**
	 * loads the array $this->gestalt of this bean for use with Model::gestalt().
	 */
	public function loadGestalten()
	{
		$this->gestalt['autoTags'] = false;
		// the default gestalt
		$this->gestalt['default'] = array(
			array(
				'type' => 'select',
				'name' => 'model',
				'help' => __('entry_model_help'),
				'parameters' => array(
					'options' => array(
						'todo' => __('entry_type_option_todo'),
						'event' => __('entry_type_option_event'),
						'project' => __('entry_type_option_project'),
						'addressbook' => __('entry_type_option_addressbook'),
						'template' => __('entry_type_option_template'),
						'page' => __('entry_type_option_webpage'),
						'media' => __('entry_type_option_media'),
						'user' => __('entry_type_option_user'),
						'language' => __('entry_type_option_language'),
						'country' => __('entry_type_option_country'),
						'rbac_role' => __('entry_type_option_rbac_role'),
						'rbac_domain' => __('entry_type_option_rbac_domain'),
						'rbac_action' => __('entry_type_option_rbac_action'),
						'rbac' => __('entry_type_option_rbac')
					)
				)
			),
			array(
				'type' => 'hidden',
				'name' => 'creation_date',
				'parameters' => array(
					'readonly' => 'readonly'
				)
			),
			array(
				'type' => 'hidden',
				'name' => 'modification_date',
				'parameters' => array(
					'readonly' => 'readonly'
				)
			)
		);
	}
	
	/**
	 * sets the record taht this entry escorts.
	 *
	 * @param mixed $record
	 */
	public function setRecord($record)
	{
		$this->record = $record;
	}
	
	/**
	 * validates the data and returns either true or false.
	 *
	 * @return bool
	 */
	public function validate()
	{
		$valid = true;
		return $valid;
	}

	/**
	 * open.
	 */
	public function open()
	{
	}

	/**
	 * dispense.
	 */
	public function dispense()
	{
	}

	/**
	 * update.
	 */
	public function update()
	{
		$now = date('Y-m-d H:i:s');
		if ( ! $this->bean->getId()) {
			$this->bean->model = $this->record->getMeta('type');
			$this->bean->revision = 0;
			$this->bean->creation_date = $now;
			$this->bean->creation_user = $this->controller()->user();
		}
		$this->bean->revision++;
		$this->bean->modification_date = $now;
		$this->bean->modification_user = $this->controller()->user();
		$this->bean->location = $this->controller()->user()->location;
	}
	
	/**
	 * after_update.
	 */
	public function after_update()
	{
	}
	
	/**
	 * delete.
	 */
	public function delete()
	{
	}
	
	/**
	 * after_delete.
	 */
	public function after_delete()
	{
	}
}
?>